#include<stdio.h>
#include<math.h>
#include<iostream>
using namespace std;

int gcd(int a,int b)
{
    
    while(b!=0)
    {
        int temp = b;
        b = a%b;
        a = temp;




    }
    return a;

}

int main()
{
int t = 0;
cin>>t;
while (t--)

{
    int x = 0;
    cin>>x;

   int shi =-1;
    int max_y = 0;
    for (int y = 1;  y< x; y++)
    {
        int gcd1 = gcd(y,x);
        int end = gcd1*(y+1)+y;
        

        if(end>shi)
        {
            shi = end;  
            max_y =y;


        }


    }
    
cout<<max_y<<endl;





}








    return 0;
}